package com.riteny.paymentgateway.swifypass.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.dom4j.Element;

/**
 * @author Riteny
 * 2021/7/1  10:32
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class SwiftPassQueryPaymentOrderResponseEntity {

    public SwiftPassQueryPaymentOrderResponseEntity(Element responseXml) {

        setVersion(responseXml.elementText("version"));
        setCharset(responseXml.elementText("charset"));
        setSignType(responseXml.elementText("sign_type"));
        setStatus(responseXml.elementText("status"));
        setMessage(responseXml.elementText("message"));
        setResultCode(responseXml.elementText("result_code"));
        setMchId(responseXml.elementText("mch_id"));
        setDeviceInfo(responseXml.elementText("device_info"));
        setNonceStr(responseXml.elementText("nonce_str"));
        setErrCode(responseXml.elementText("err_code"));
        setErrMsg(responseXml.elementText("err_msg"));
        setSign(responseXml.elementText("sign"));

        setTradeState(responseXml.elementText("trade_state"));
        setTradeType(responseXml.elementText("trade_type"));
        setOpenid(responseXml.elementText("openid"));
        setTransactionId(responseXml.elementText("transaction_id"));
        setOutTransactionId(responseXml.elementText("out_transaction_id"));
        setOutTradeNo(responseXml.elementText("out_trade_no"));

        if (StringUtils.isNotEmpty(responseXml.elementText("total_fee"))) {
            setTotalFee(Integer.valueOf(responseXml.elementText("total_fee")));
        }

        if (StringUtils.isNotEmpty(responseXml.elementText("coupon_fee"))) {
            setCouponFee(Integer.valueOf(responseXml.elementText("coupon_fee")));
        }

        setFeeType(responseXml.elementText("fee_type"));
        setAttach(responseXml.elementText("attach"));
        setBankType(responseXml.elementText("bank_type"));
        setBankBillno(responseXml.elementText("bank_billno"));

        setTimeEnd(responseXml.elementText("time_end"));

        //中銀參數
        setLocalFeeType(responseXml.elementText("local_fee_type"));
        if (StringUtils.isNotEmpty(responseXml.elementText("local_total_fee"))) {
            setLocalTotalFee(Integer.valueOf(responseXml.elementText("local_total_fee")));
        }
        if (StringUtils.isNotEmpty(responseXml.elementText("order_fee"))) {
            setOrderFee(Integer.valueOf(responseXml.elementText("order_fee")));
        }
    }

    private String version;

    private String charset;

    private String signType;

    private String status;

    private String message;

    private String resultCode;

    private String mchId;

    private String deviceInfo;

    private String nonceStr;

    private String errCode;

    private String errMsg;

    private String sign;


    private String tradeState;

    private String tradeType;

    private String openid;

    private String transactionId;

    private String outTransactionId;

    private String outTradeNo;

    private Integer totalFee;

    private Integer couponFee;

    private String feeType;

    private String attach;

    private String bankType;

    private String bankBillno;

    private String timeEnd;


    private String localFeeType;

    private Integer localTotalFee;

    private Integer orderFee;
}
